<script setup>
import { onMounted, ref } from 'vue'
import Tabs from '@/components/tabs/index.vue'
import TaskDetail from './components/TaskDetail.vue'
import InspectionInfo from './components/InspectionInfo.vue'
import DangerNoticeForm from './components/DangerNoticeForm.vue'
import { useRouter, useRoute } from 'vue-router'
import { getSpecialDetail } from '@/api/manager/inspectionManage/specialManage.js'
import { useDict } from '@/hooks/useDict'
const { dict, getDictStyle, getDictValue } = useDict([
  'special_task_type',
  'special_task_publish_scope',
  'inspection_status',
])

const router = useRouter()
const route = useRoute()
const form = ref({})
const tabsConfig = ref([])
const currentComponentKey = ref('')

const handleDetail = async () => {
  const res = await getSpecialDetail({ pkid: route.query.pkid })
  res.data.attachmentFiles = res.data.attachmentFiles
    ? res.data.attachmentFiles
    : []
  res.data.attachmentVideos = res.data.attachmentVideos
    ? res.data.attachmentVideos
    : []
  res.data.coverImages = res.data.coverImages ? res.data.coverImages : []
  form.value = res.data
  if (res.data.taskType === '1') {
    tabsConfig.value = [
      {
        name: '任务详情',
        value: 'detail',
      },
      {
        name: '通知模版',
        value: 'notice',
      },
      {
        name: '查阅情况',
        value: 'view',
      },
    ]
  } else {
    tabsConfig.value = [
      {
        name: '任务详情',
        value: 'detail',
      },
      {
        name: '查阅情况',
        value: 'view',
      },
    ]
  }
  currentComponentKey.value = 'detail'
}
onMounted(() => {
  if (route.query.pkid) {
    handleDetail()
  }
})
</script>

<template>
  <div class="detail-wrapper">
    <div class="header">
      {{ form.name }}
      <el-tag :type="getDictStyle('inspection_status', form.taskStatus)">
        {{ getDictValue('inspection_status', form.taskStatus) }}
      </el-tag>
    </div>
    <Tabs
      @change="(val) => (currentComponentKey = val)"
      :currentKey="currentComponentKey"
      :tabsConfig="tabsConfig"
    />
    <div class="detail">
      <TaskDetail v-show="currentComponentKey === 'detail'" :detail="form" />
      <div class="detail-content" v-show="currentComponentKey === 'notice'">
        <DangerNoticeForm :readonly="true" v-if="form.templeteType === '1'" />
      </div>
      <InspectionInfo
        v-show="currentComponentKey === 'view'"
        :tableData="form.specialLearnInfos"
        :templeteContent="form.templeteContent"
        :taskType="form.taskType"
      />
    </div>
  </div>
</template>

<style scoped lang="scss">
.detail-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  box-shadow: 0 0 10px 0 rgba(72, 121, 238, 0.1);
  .header {
    width: 100%;
    height: 54px;
    box-sizing: border-box;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    font-weight: 400;
    font-size: 16px;
    color: #333333;
    border-bottom: 1px solid #dee4ed;
    .el-tag {
      margin-left: 20px;
    }
  }
  .tabs-wrapper {
    box-shadow: none;
    background: #f3f7fe;
  }
  .detail {
    width: 100%;
    flex: 1;
    box-sizing: border-box;
    padding: 20px 30px;
    overflow-y: auto;
    &-content {
      width: 100%;
      box-sizing: border-box;
      padding: 20px 0;
      display: flex;
      justify-content: center;
    }
  }
}
</style>
